package com.zenithmind.library.service;

import com.zenithmind.common.result.PageResult;
import com.zenithmind.common.result.Result;
import com.zenithmind.library.pojo.dto.BookAuthorCreateDTO;
import com.zenithmind.library.pojo.query.BookAuthorQuery;
import com.zenithmind.library.pojo.vo.BookAuthorVO;

import java.util.List;

/**
 * 图书作者关联服务接口
 * 遵循接口隔离原则：只包含图书作者关联相关的业务方法
 * 遵循单一职责原则：专门负责图书与作者的多对多关联关系管理
 * 
 * @author ZenithMind
 * @since 2024-06-14
 */
public interface BookAuthorService {

    /**
     * 分页查询图书作者关联
     * 
     * @param query 查询条件
     * @return 分页结果
     */
    PageResult<BookAuthorVO> getBookAuthorPage(BookAuthorQuery query);

    /**
     * 根据图书ID查询所有作者
     * 
     * @param bookId 图书ID
     * @return 作者列表
     */
    Result<List<BookAuthorVO>> getAuthorsByBookId(String bookId);

    /**
     * 根据作者ID查询所有图书
     * 
     * @param authorId 作者ID
     * @return 图书列表
     */
    Result<List<BookAuthorVO>> getBooksByAuthorId(String authorId);

    /**
     * 为图书添加作者
     * 
     * @param bookId 图书ID
     * @param authorId 作者ID
     * @param authorRole 作者角色（主要作者、合著者等）
     * @param authorOrder 作者顺序
     * @return 添加结果
     */
    Result<BookAuthorVO> addAuthorToBook(String bookId, String authorId, String authorRole, Integer authorOrder);

    /**
     * 批量为图书添加作者
     * 
     * @param bookId 图书ID
     * @param bookAuthors 作者关联列表
     * @return 添加结果
     */
    Result<List<BookAuthorVO>> batchAddAuthorsToBook(String bookId, List<BookAuthorCreateDTO> bookAuthors);

    /**
     * 从图书中移除作者
     * 
     * @param bookId 图书ID
     * @param authorId 作者ID
     * @return 移除结果
     */
    Result<Void> removeAuthorFromBook(String bookId, String authorId);

    /**
     * 批量从图书中移除作者
     * 
     * @param bookId 图书ID
     * @param authorIds 作者ID列表
     * @return 移除结果
     */
    Result<Void> batchRemoveAuthorsFromBook(String bookId, List<String> authorIds);

    /**
     * 更新图书作者关联信息
     * 
     * @param bookId 图书ID
     * @param authorId 作者ID
     * @param authorRole 作者角色
     * @param authorOrder 作者顺序
     * @return 更新结果
     */
    Result<BookAuthorVO> updateBookAuthor(String bookId, String authorId, String authorRole, Integer authorOrder);

    /**
     * 检查图书作者关联是否存在
     * 
     * @param bookId 图书ID
     * @param authorId 作者ID
     * @return 是否存在
     */
    boolean existsBookAuthor(String bookId, String authorId);

    /**
     * 获取图书的主要作者
     * 
     * @param bookId 图书ID
     * @return 主要作者
     */
    Result<BookAuthorVO> getPrimaryAuthor(String bookId);

    /**
     * 设置图书的主要作者
     * 
     * @param bookId 图书ID
     * @param authorId 作者ID
     * @return 设置结果
     */
    Result<Void> setPrimaryAuthor(String bookId, String authorId);

    /**
     * 调整作者顺序
     * 
     * @param bookId 图书ID
     * @param authorOrders 作者顺序映射（作者ID -> 顺序）
     * @return 调整结果
     */
    Result<Void> adjustAuthorOrder(String bookId, List<AuthorOrderDTO> authorOrders);

    /**
     * 复制图书的作者关联到另一本图书
     * 
     * @param sourceBookId 源图书ID
     * @param targetBookId 目标图书ID
     * @return 复制结果
     */
    Result<List<BookAuthorVO>> copyBookAuthors(String sourceBookId, String targetBookId);

    /**
     * 获取作者的图书统计
     * 
     * @param authorId 作者ID
     * @return 统计信息
     */
    Result<AuthorBookStatisticsVO> getAuthorBookStatistics(String authorId);

    /**
     * 获取图书的作者统计
     * 
     * @param bookId 图书ID
     * @return 统计信息
     */
    Result<BookAuthorStatisticsVO> getBookAuthorStatistics(String bookId);

    /**
     * 导入图书作者关联数据
     * 
     * @param bookAuthors 关联数据列表
     * @return 导入结果
     */
    Result<String> importBookAuthors(List<BookAuthorCreateDTO> bookAuthors);

    /**
     * 导出图书作者关联数据
     * 
     * @param query 查询条件
     * @return 导出结果
     */
    Result<String> exportBookAuthors(BookAuthorQuery query);

    /**
     * 作者顺序DTO
     */
    class AuthorOrderDTO {
        private String authorId;
        private Integer order;

        public String getAuthorId() { return authorId; }
        public void setAuthorId(String authorId) { this.authorId = authorId; }
        
        public Integer getOrder() { return order; }
        public void setOrder(Integer order) { this.order = order; }
    }

    /**
     * 作者图书统计VO
     */
    class AuthorBookStatisticsVO {
        private Integer totalBooks;
        private Integer primaryAuthorBooks;
        private Integer coAuthorBooks;
        private Integer translatorBooks;
        private Integer editorBooks;

        public Integer getTotalBooks() { return totalBooks; }
        public void setTotalBooks(Integer totalBooks) { this.totalBooks = totalBooks; }
        
        public Integer getPrimaryAuthorBooks() { return primaryAuthorBooks; }
        public void setPrimaryAuthorBooks(Integer primaryAuthorBooks) { this.primaryAuthorBooks = primaryAuthorBooks; }
        
        public Integer getCoAuthorBooks() { return coAuthorBooks; }
        public void setCoAuthorBooks(Integer coAuthorBooks) { this.coAuthorBooks = coAuthorBooks; }
        
        public Integer getTranslatorBooks() { return translatorBooks; }
        public void setTranslatorBooks(Integer translatorBooks) { this.translatorBooks = translatorBooks; }
        
        public Integer getEditorBooks() { return editorBooks; }
        public void setEditorBooks(Integer editorBooks) { this.editorBooks = editorBooks; }
    }

    /**
     * 图书作者统计VO
     */
    class BookAuthorStatisticsVO {
        private Integer totalAuthors;
        private Integer primaryAuthors;
        private Integer coAuthors;
        private Integer translators;
        private Integer editors;

        public Integer getTotalAuthors() { return totalAuthors; }
        public void setTotalAuthors(Integer totalAuthors) { this.totalAuthors = totalAuthors; }
        
        public Integer getPrimaryAuthors() { return primaryAuthors; }
        public void setPrimaryAuthors(Integer primaryAuthors) { this.primaryAuthors = primaryAuthors; }
        
        public Integer getCoAuthors() { return coAuthors; }
        public void setCoAuthors(Integer coAuthors) { this.coAuthors = coAuthors; }
        
        public Integer getTranslators() { return translators; }
        public void setTranslators(Integer translators) { this.translators = translators; }
        
        public Integer getEditors() { return editors; }
        public void setEditors(Integer editors) { this.editors = editors; }
    }
}
